home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / wattcp / src / pcsed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  3.0 KB  |  122 lines

  1. /*
  2.  * Ethernet Driver Routines
  3.  *
  4.  *  The TCP code uses Ethernet constants for protocol numbers and 48 bits
  5.  *  for address.  Also, 0xffffffffffff is assumed to be a broadcast.
  6.  *
  7.  *  If you need to write a new driver, implement it at this level and use
  8.  *  the above mentioned constants as this program's constants, not device
  9.  *  dependant constants.
  10.  *
  11.  *  The packet driver code lies below this and really ought to be rewritten
  12.  *  in assembly language.
  13.  *
  14.  *  _eth_addr      - Ethernet address of this host.
  15.  *  _eth_brdcast - Ethernet broadcast address.
  16.  */
  17. #include"capalloc.h"
  18. #include"capstdio.h"
  19. #include <copyright.h>
  20. #include <wattcp.h>
  21. #include <ethdev.h>
  22. #include <mem.h>
  23.  
  24. eth_address _eth_addr;        /* local ethernet address */
  25. eth_address _eth_brdcast;    /* Ethernet broadcast address */
  26. word _pktdevclass = 1;        /* Ethernet = 1, SLIP = 6 */
  27.  
  28. /*
  29.  *  Initialize the Ethernet Interface, and this package.  Enable input on
  30.  *  all packet buffers.
  31.  */
  32. void _eth_init()
  33. {
  34.     movmem( _pkt_eth_init() , _eth_addr, 6 );
  35.     memset( &_eth_brdcast, 0xff, sizeof( _eth_brdcast ));
  36. }
  37.  
  38. /*
  39.  * _eth_FormatPacket places the next packet into the buffer and uses the
  40.  * type field for protocol determination.  Note, I only maintain a single
  41.  * output buffer, and it gets used quickly then released.  The benefits of
  42.  * non-blocking systems are immense.
  43.  */
  44.  
  45. static struct ether outbuf;
  46.  
  47. byte *_eth_formatpacket( void *eth_dest, word eth_type )
  48. {
  49.     memset( &outbuf, 0, sizeof(struct ether));
  50.     switch ( _pktdevclass ) {
  51.     case PD_ETHER :
  52.         movmem( eth_dest, outbuf.dest, 6 );
  53.                 movmem( _eth_addr, outbuf.src, 6 );
  54.         outbuf.type = eth_type;
  55.                 return( (byte *)&outbuf.data );
  56.     case PD_SLIP :
  57.                 return( (byte *) &outbuf );      /* no header */
  58.     }
  59. }
  60.  
  61. /*
  62.  * _eth_send does the actual transmission once we are complete with the
  63.  * buffer.  Do any last minute patches here, like fix the size.
  64.  */
  65. int _eth_send( word len)
  66. {
  67.  
  68.     if (( _pktdevclass == PD_ETHER ) && ((len += 14) < ETH_MIN ))
  69.     len = ETH_MIN;
  70.  
  71.     return( pkt_send( &outbuf, len ));   /* send to packet driver */
  72. }
  73.  
  74. /*
  75.  * _eth_free - free an input buffer once it is no longer needed
  76.  * If pointer to NULL, release all buffers
  77.  */
  78. void _eth_free( void *buf)
  79. {
  80.     if ( buf )
  81.     pkt_buf_release( buf );
  82.     else
  83.     pkt_buf_wipe();
  84. }
  85.  
  86. /*
  87.  * _eth_arrived - if a new packet has arrived, read it and fill pointer
  88.  * with type of packet
  89.  */
  90.  
  91. byte *_eth_arrived( word *type_ptr)
  92. {
  93.     struct ether * temp;
  94.  
  95.     if ((temp = (struct ether * ) pkt_received()) != NULL ) {
  96.     switch ( _pktdevclass ) {
  97.         case PD_ETHER : *type_ptr = temp->type;
  98.                 return( temp->data );
  99.         case PD_SLIP  : *type_ptr = 0x008;
  100.                 return( (byte *) temp );
  101.     }
  102.     }
  103.     return( NULL );
  104. }
  105.  
  106. /*
  107.  * _eth_release - release the hardware
  108.  */
  109. void _eth_release()
  110. {
  111.     pkt_release();
  112. }
  113.  
  114. /*
  115.  * _eth_hardware - return pointer to hardware address of a packet
  116.  */
  117. void *_eth_hardware( byte *p )
  118. {
  119.     return( p - 8 );
  120. }
  121.  
  122.